#! /usr/bin/env python
"""
Nagios Plugin that checks the Kernelversion of the System.
"""
__author__ = "Tobias Scherer, grid@switch.ch"
__copyright__ = "Copyright 2010, SMSCG an AAA/SWITCH project"
__date__ = "28.09.2010"
__version__ = "0.1"

from os import uname
import sys
from nagios_plugin import NagiosPluginBasic
from nagios_plugin import RETURN_CODE

# Indices of os.uname() return value
SYSNAME = 0
NODENAME = 1
RELEASE = 2
VERSION = 3
MACHINE = 4

class KernelVersion(NagiosPluginBasic):
	"""
	Query version of the installed kernel.
	"""
	def __init__(self):
		parser = NagiosPluginBasic.getOptions(self)
		parser.remove_option("-c")
		parser.remove_option("-w")
		parser.remove_option("-H")
		parser.parse_args()
		
	def main(self):
		result = uname()
		if result[RELEASE] != '':
			print "OK: %s Kernel Version %s " % (result[SYSNAME], result[RELEASE])
			sys.exit(RETURN_CODE["ok"])
		else:
			print "UNKNOWN: Cannot find out kernel version"
			sys.exit(RETURN_CODE["unknown"])
		
if __name__ =="__main__":
	g = KernelVersion()
	g.main()